home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp95 / freyja13.exe / lha / SMJAGUAR.C < prev    next >
C/C++ Source or Header  |  1992-03-22  |  20KB  |  889 lines

  1. /* SMJAGUAR.C -- HP95LX (Jaguar) Commands and Support, System-Manager Compliant
  2.  
  3.     Written March 1992 by Craig A. Finseth
  4.     Copyright 1992 by Craig A. Finseth
  5.  
  6. NOTE: This entire file is only compiled and linked on IBM PC (MSDOS)
  7. systems and for the system-manager compliant version.  Therefore, no
  8. #ifdef's are required. */
  9.  
  10. #include "freyja.h"
  11.  
  12. /* The following are excerpts from files Copyright 1990 by
  13. Hewlett-Packard and Copyright 1990 by Lotus Development Corporation. */
  14.  
  15. /* ============================================================ */
  16. /* #include "headers/mdit.h" */
  17.  
  18. typedef struct {
  19.     char    far *m_buffer;    /*  user-supplied edit buffer  */
  20.     int     m_length;         /*  length of buffer  */
  21.     int     m_pos;            /*  current cursor position  */
  22.     int     m_row, m_col;     /*  location of edit area  */
  23.     int     m_nrows, m_ncols; /*  dimensions of edit area  */
  24.     int    m_yoff,m_disprows;/*  current top row, number of rows displayable */
  25.     char    m_ccol;           /*  cursor column  */
  26.     char    m_modified;       /*  1 -> buffer has been modified  */
  27.         char    m_xoff;           /*  1st disp. col (for ticker fields only)*/
  28.         char    wrapflag;         /*  1 -> wordwrap enabled,-1 ticker field */
  29.     int     far *m_line;      /*  pointer to array used for line starts */
  30.                   /*     must be at least m_nrows+1 long */
  31.     char     markon;          /* currenty marking? */
  32.     char    spec_flag;
  33.     int    markst;          /* offset of start of mark, inclusive */
  34.     int    markend;      /* offset of end of mark, inclusive */
  35.         int     m_dispcols;       /*  displayable columns */
  36. } MDITDATA;
  37.  
  38.  
  39. /* ============================================================ */
  40. /* #include "headers/edit.h" */
  41.  
  42. typedef struct {
  43.     int edit_length;     /* current length of the edit buffer */
  44.     char first_time;          /* flag for special processing on first char */
  45.     char spec_flags;    /* bit 0 is tab handling */
  46.          int prompt_window;      /* whether this belongs to the prompt window */
  47.     char far *message_line; /* the top line message for prompt */
  48.     int message_line_length;/* length of same */
  49.     char far *prompt_line;  /* second line of prompt window */
  50.     int prompt_line_length; /* length of same */
  51.     char edit_buffer[80];   /* work space for the buffer */
  52.     int  line_array[2];    /* line array needed by mdit */
  53.     MDITDATA mdit;          /* multi-line edit structure */
  54.     int e_dispcols;
  55. } EDITDATA;
  56.  
  57. /* ============================================================ */
  58. /* #include "headers/event.h" */
  59.  
  60. enum event_kind {
  61.     E_NONE,        /* no events available */
  62.     E_KEY,        /* keystroke available */
  63.     E_BREAK,    /* CNTRL_BREAK encountered */
  64.     E_ACTIV,    /* reactivation event, always follows E_DEACT */
  65.     E_DEACT,    /* about to sleep, next event request is delayed */
  66.     E_TERM,        /* forced closure of application */
  67.     E_BRIDGE,    /* 123 bridge service request, only ret. to 123 */
  68.     E_GROW,         /* request to 123 to grow */
  69.     E_SHRINK,    /* request to 123 to shrink */
  70.     E_ALARM_EXP,    /* application's alarm has expired */
  71.     E_ALARM_DAY,    /* daily chance to set an alarm */
  72.     E_TIMECHANGE    /* system date or time has been changed */
  73. };
  74.  
  75. typedef struct {
  76.     enum event_kind kind;
  77.     unsigned int data;    /* ASCII (CP 850) translation of keystroke */
  78.     unsigned char scan;    /* scan code from BIOS */
  79.     unsigned char shifts;    /* shifts register, when function returns */
  80.                 /* not necessarily when key struck */
  81.     unsigned int lics;    /* LICS translation of keystroke */
  82.     unsigned char fkey_num;    /* function key number for 123 only */
  83.     void far * bridge;    /* pointer to 123 bridge data structure */
  84. } EVENT;
  85.  
  86.  
  87. /* ============================================================ */
  88. /* #include "headers/fmenu.h" */
  89.  
  90. /* define return codes */
  91.  
  92. #define    RET_BADFILE        -5
  93. #define    RET_BADDIR        -4
  94. #define    RET_BADDRIVE    -3
  95. #define    RET_UNKNOWN        -2
  96. #define    RET_BAD            -1
  97. #define    RET_OK            0
  98. #define    RET_REDISPLAY    1
  99. #define    RET_ACCEPT        2
  100. #define    RET_ABORT        3
  101.  
  102. /* file info structures created in FM_BUFFER */
  103. typedef    struct {
  104.     char fi_attr;                /*  file attribute  */
  105.     int fi_time;                /*  time modified  */
  106.          int fi_date;                /*  date modified  */
  107.     long fi_size;                  /*  file length  */
  108.          char fi_name[13];            /*  file name  */
  109. } FILEINFO;                                  
  110.  
  111. /* define the menu structure */
  112. typedef struct {
  113.     char far *fm_path;        /* base directory name C:\DATA\ */
  114.     char far *fm_pattern;        /* file pattern, e.g.  *.WK1    */
  115.     FILEINFO far *fm_buffer;    /* workspace  for file list (hold finfos) */
  116.     int fm_buf_size;        /* size of the buffer in bytes */
  117.          int fm_startline,fm_startcol;    /* starting row,col */
  118.     int fm_numlines, fm_numcols;    /* number of lines and columns */
  119.     int fm_filesperline;        /* nuumber of files displayed across */
  120. /* -- Initted in service -- */
  121.     int fm_firstedit;            /* 0 if first edit char, else multi line */
  122.     int fm_filesinbuf;        /* number of files in list */
  123.     int fm_maxfinbuf;        /* maximum number of files buffer holds */
  124.     int fm_topfile;            /* file at top of list */
  125.     int fm_curselect;        /* index of file to highlight */
  126.     int fm_oldselect;        /* index of file to un-highlight */
  127.     int fm_focus;            /* 1 = fmenu, 2 = edit */
  128. } FMENU;
  129.  
  130.  
  131. /* ============================================================ */
  132. /*#include "headers/menu.h"*/
  133.  
  134. #define   MAX_KWDS    20
  135. #define   MAX_MENU     3
  136. #define   MAX_MWID     80
  137.  
  138. typedef struct {
  139.      char menu_text [MAX_MENU][MAX_MWID];
  140.      int menu_count;
  141.      int menu_highlight;
  142.      int menu_tprompt;
  143.      char menu_line   [MAX_KWDS];
  144.      char menu_offset [MAX_KWDS];
  145.      char menu_length [MAX_KWDS];
  146.      char menu_letter [MAX_KWDS];
  147.     unsigned menu_prompt[MAX_KWDS];
  148.      } MENUDATA;
  149.  
  150.  
  151. /* ============================================================ */
  152. /*#include "headers/settings.h"*/
  153.  
  154. #define MAX_MACRO_LEN    256
  155. #define NAMEBUFLEN    30
  156. #define TITLEBUFLEN    30
  157. #define COMPANYBUFLEN    28
  158.  
  159. /*  settings */
  160. typedef struct {
  161.     int    Country;    /* */
  162.     int    Volume;     /* 1 speaker volume level 0ffh for off and 0-3 */
  163.     int    Contrast;    /* 2 contrast level 1-5 */
  164.     int    WeekStart;    /* 3 week starts SUNDAY or Monday */
  165.     int    Punctuation;    /* 4 Punctuation format */
  166.     int     Language;    /* two character code for current language */
  167.     int    DateFormat;    /* 6 current date format */
  168.     int    TimeFormat;    /* 7 current time format */
  169.     int    Sort;        /* 8 collating sequence */
  170.     char    PicFile[80];    /* picture file name */
  171.     char    Name_Buff[NAMEBUFLEN];    
  172.     char    Title_Buff[TITLEBUFLEN]; 
  173.     char    Company_Buff[COMPANYBUFLEN]; 
  174.     int     LanguageCount;
  175.     int    LanguagesAvail[6];    /* MAX_LANG */
  176.     char    LanguageMenu[66];    
  177.  
  178.     char    DateSeparator[2]; /* date separator  can be /-. */
  179.     char    TimeSeparator[2]; /* time separator can be :., or h (for hms) */
  180.     char    DateOrder;    /* */
  181.     char    Time24;        /* use 24 hour time? */
  182.  
  183.     char    Currency[16];   /* currency string */
  184.     int    CurrencyFix;   /* prefix or sufix */
  185.  
  186.     int    Keyboard;
  187.     int    PrBaud;     /* printer baud rate */
  188.     int    PrDriver;    /* epson, hp, etc, by code */
  189.     int     PrInterface;    /* com 1, etc  */
  190.     int    SystemRupt;        /* sysmgr interupt number - 60 default */
  191.     int    CodePage;        /* for PC based - 437 or 850 based */
  192.     int    ExitKeyCode;    /* for PC based - active exit key */
  193.     int    MenuKeyCode;    /* for PC based - active menu key */
  194.     int    CharKeyCode;    /* for PC based - active CHAR key toggle */
  195.     int    Alarm[6];
  196. } SETTINGS;
  197.  
  198.  
  199. typedef struct {
  200.     char    MacroFK;       /* MacroFunctionKey Number 1-10 0 for not used */
  201.         unsigned char MacroSize;   /* elements in the macro */
  202.         char    CommentString[38]; /* MacroFunctionKey's Comment line */
  203.     unsigned int MacroBody[MAX_MACRO_LEN];
  204. } MACROHD;
  205.  
  206.  
  207. /* ============================================================ */
  208. /* #include "headers/time.h" */
  209. typedef struct {
  210.     int    dt_year;
  211.     char    dt_month;
  212.     char    dt_date;
  213.     char    dt_day;
  214.     char    dt_hour;
  215.     char    dt_minute;
  216.     char    dt_second;
  217.     char    dt_hundreth;
  218. } DTM;
  219.  
  220.  
  221. /* ============================================================ */
  222. /* #include "headers/interfac.h" */
  223.  
  224. #define SC_EVENT    1
  225. #define SC_MENU     2
  226. #define SC_SCREEN    3
  227. #define SC_FILE     5
  228. #define SC_PM        6
  229. #define SC_CB        7
  230. #define SC_DTIME    11
  231. #define SC_MISC     15
  232.  
  233. #define F_M_EVENT    (SC_EVENT * 256) + 0
  234. #define m_event(a)    \
  235.     c_service(F_M_EVENT,(void far *)(a) )
  236.  
  237. #define F_M_NEVENT    (SC_EVENT * 256) + 1
  238. #define m_nevent(a)    \
  239.     c_service(F_M_NEVENT,(void far *)(a))
  240.  
  241. #define F_M_NO_FINI    (SC_EVENT * 256) + 7
  242. #define m_no_fini(a)    \
  243.     c_service(F_M_NO_FINI,(void far *)(a) )
  244.  
  245.  
  246.  
  247. #define F_MENU_SETUP    (SC_MENU * 256) + 0
  248. #define menu_setup(a,b,c,d,e,f,g)    \
  249.     c_service(F_MENU_SETUP,(void far *)(a),(void far *)(b), \
  250.         (c),(d),(void far *)(e),(f),(void far *)(g) )
  251.  
  252. #define F_MENU_DIS    (SC_MENU * 256) + 1
  253. #define menu_dis(a)    \
  254.     c_service(F_MENU_DIS,(void far *)(a))
  255.  
  256. #define F_MENU_ON    (SC_MENU * 256) + 2
  257. #define menu_on(a)    \
  258.     c_service(F_MENU_ON,(void far *)(a))
  259.  
  260. #define F_MENU_OFF    (SC_MENU * 256) + 3
  261. #define menu_off(a)    \
  262.     c_service(F_MENU_OFF,(void far *)(a))
  263.  
  264. #define F_MENU_KEY    (SC_MENU * 256) + 4
  265. #define menu_key(a,b,c) \
  266.     c_service(F_MENU_KEY,(void far *)(a),(b),(void far *)(c))
  267.  
  268. #define F_FMENU_INIT      (SC_MENU * 256) + 5
  269. #define fmenu_init(a,b,c,d,e)      \
  270.     c_service(F_FMENU_INIT,(void far *)(a),(void far *)(b),(char far *)(c),(d),(e))
  271.  
  272. #define F_FMENU_DIS     (SC_MENU * 256) + 6
  273. #define fmenu_dis(a,b)      \
  274.     c_service(F_FMENU_DIS,(void far *)(a),(void far *)(b))
  275.  
  276. #define F_FMENU_KEY     (SC_MENU * 256) + 7
  277. #define fmenu_key(a,b,c) \
  278.     c_service(F_FMENU_KEY,(void far *)(a),(void far *)(b),(c))
  279.  
  280. #define F_FMENU_OFF      (SC_MENU * 256) + 8
  281. #define fmenu_off(a,b)     \
  282.     c_service(F_FMENU_OFF,(void far *)(a),(void far *)(a))
  283.  
  284.  
  285.  
  286. #define F_M_CLEAR    (SC_SCREEN * 256) + 1
  287. #define m_clear(a,b,c,d)         \
  288.     c_service(F_M_CLEAR,a,b,c,d)
  289.  
  290.  
  291.  
  292. #define F_M_GET_SYSDIR    (SC_FILE * 256) + 22
  293. #define m_get_sysdir(a)           \
  294.     c_service(F_M_GET_SYSDIR,(void far *)(a))
  295.  
  296.  
  297.  
  298. #define F_M_INIT    (SC_PM * 256) + 0
  299. #define m_init()    c_service(F_M_INIT)
  300.  
  301. #define F_M_FINI    (SC_PM * 256) + 1
  302. #define m_fini()    c_service(F_M_FINI)
  303.  
  304. #define F_M_LOCK    (SC_PM * 256) + 2
  305. #define m_lock()    c_service(F_M_LOCK)
  306.  
  307. #define F_M_UNLOCK    (SC_PM * 256) + 3
  308. #define m_unlock()    c_service(F_M_UNLOCK)
  309.  
  310.  
  311.  
  312. #define F_M_OPEN_CB    (SC_CB * 256) + 0
  313. #define m_open_cb()        \
  314.     c_service(F_M_OPEN_CB)
  315.  
  316. #define F_M_CLOSE_CB    (SC_CB * 256) + 1
  317. #define m_close_cb()        \
  318.     c_service(F_M_CLOSE_CB)
  319.  
  320. #define F_M_RESET_CB    (SC_CB * 256) + 2
  321. #define m_reset_cb(a)        \
  322.     c_service(F_M_RESET_CB,(void far *)(a))
  323.  
  324. #define F_M_NEW_REP    (SC_CB * 256) + 4
  325. #define m_new_rep(a)         \
  326.     c_service(F_M_NEW_REP,(void far *)(a))
  327.  
  328. #define F_M_FINI_REP    (SC_CB * 256) + 5
  329. #define m_fini_rep()        \
  330.     c_service(F_M_FINI_REP)
  331.  
  332. #define F_M_REP_INDEX    (SC_CB * 256) + 7
  333. #define m_rep_index(a,b,c)    \
  334.     c_service(F_M_REP_INDEX,(void far *)(a),(void far *)(b),(void far *)(c))
  335.  
  336. #define F_M_CB_WRITE    (SC_CB * 256) + 8
  337. #define m_cb_write(a,b)     \
  338.     c_service(F_M_CB_WRITE,(void far *)(a),b)
  339.  
  340. #define F_M_CB_READ    (SC_CB * 256) + 9
  341. #define m_cb_read(a,b,c,d)    \
  342.     c_service(F_M_CB_READ,a,b,(void far *)(c),d)
  343.  
  344.  
  345.  
  346. #define F_M_GETDTM    (SC_DTIME * 256) + 1
  347. #define m_getdtm(a)          \
  348.     c_service(F_M_GETDTM,(void far *)(a))
  349.  
  350. #define F_M_GET_SETTINGS (SC_DTIME *256) +9
  351. #define m_get_settings(a,b)      \
  352.     c_service(F_M_GET_SETTINGS, (void far *)(a),(void far *)(b))
  353.  
  354.  
  355.  
  356. #define F_MESSAGE    (SC_MISC * 256) + 3
  357. #define message(a,b,c,d)           \
  358.     c_service(F_MESSAGE,(void far *)(a),b,(void far *)(c),d)
  359.  
  360. #define F_MSG_OFF    (SC_MISC * 256) + 4
  361. #define msg_off()        \
  362.     c_service(F_MSG_OFF)
  363.  
  364. /* ============================================================ */
  365.  
  366. static MACROHD m;
  367. static int *mac_ptr;
  368. static int mac_len;
  369.  
  370. void J_Char();        /* int which */
  371. FLAG J_Copy();        /* void */
  372. FLAG J_Paste();        /* void */
  373.  
  374. /* ------------------------------------------------------------ */
  375.  
  376. void
  377. JInit()
  378.     {
  379.     SETTINGS s;
  380.  
  381.     m_init();
  382.  
  383.     mac_len = 0;
  384.  
  385.     m_get_settings(&s, &m);
  386.     DSetup(s.WeekStart);
  387.     }
  388.  
  389.  
  390. /* ------------------------------------------------------------ */
  391.  
  392. void
  393. JFini()
  394.     {
  395.     BFini();
  396.     m_fini();
  397.     }
  398.  
  399.  
  400. /* ------------------------------------------------------------ */
  401.  
  402. /* End a redisplay. */
  403.  
  404. void
  405. JDisEnd()
  406.     {
  407.     JLightOn();
  408.     m_unlock();
  409.     }
  410.  
  411.  
  412. /* ------------------------------------------------------------ */
  413.  
  414. /* Start a redisplay. */
  415.  
  416. void
  417. JDisStart()
  418.     {
  419.     m_lock();
  420.     JLightOff();
  421.     }
  422.  
  423.  
  424. /* ------------------------------------------------------------ */
  425.  
  426. /* Return the current date. */
  427.  
  428. void
  429. JGetDate(year, mon, day)
  430.     int *year;
  431.     int *mon;
  432.     int *day;
  433.     {
  434.     DTM d;
  435.  
  436.     m_getdtm(&d);
  437.     *year = d.dt_year;
  438.     *mon = d.dt_month - 1;
  439.     *day = d.dt_day;
  440.     }
  441.  
  442.  
  443. /* ------------------------------------------------------------ */
  444.  
  445. /* Returns the default configuration file directory. DNAME must point
  446. to an FNAMEMAX-sized buffer. */
  447.  
  448. void
  449. JGetDir(dname)
  450.     char *dname;
  451.     {
  452.     m_get_sysdir(dname);
  453.     }
  454.  
  455.  
  456. /* ------------------------------------------------------------ */
  457.  
  458. /* Get a file name using the file getter.  Return True on success or
  459. False on abort. */
  460.  
  461. FLAG
  462. JGetFile(prompt, fname)
  463.     char *prompt;
  464.     char *fname;
  465.     {
  466.     FILEINFO fi[100];
  467.     FMENU f;
  468.     EDITDATA ed;
  469.     EVENT e;
  470.     FLAG isdone = FALSE;
  471.     FLAG ok = TRUE;
  472.     char dn[FNAMEMAX];
  473.     char fn[FNAMEMAX];
  474.     char f3[FNAMEMAX];
  475.     char *cptr;
  476.  
  477.     xstrcpy(dn, fname);
  478.     xstrcpy(f3, fname);
  479.     for (cptr = dn + strlen(dn); cptr > dn; --cptr) {
  480.         if (*cptr == ':' || *cptr == '/' || *cptr == '\\') break;
  481.         }
  482.     if (*cptr == ':' || *cptr == '/' || *cptr == '\\')
  483.         xstrcpy(fn, cptr + 1);
  484.     else    xstrcpy(fn, cptr);
  485.     *cptr = NUL;
  486.     if (*fn == NUL) {
  487.         xstrcpy(fn, "*.*");
  488.         strcat(f3, "*.*");
  489.         }
  490.  
  491.     f.fm_path = dn;
  492.     f.fm_pattern = fn;
  493.     f.fm_buffer = fi;
  494.     f.fm_buf_size = sizeof(fi);
  495.     f.fm_startline = -2;
  496.     f.fm_startcol = 0;
  497.     f.fm_numlines = 15;
  498.     f.fm_numcols = 40;
  499.     f.fm_filesperline = 3;
  500.  
  501.     ed.prompt_window = 1;
  502.     ed.prompt_line_length = 0;
  503.     ed.message_line = prompt;
  504.     ed.message_line_length = strlen(prompt);
  505.  
  506.     m_clear(-3, 0, 15, 40);
  507.  
  508.     if (fmenu_init(&f, &ed, f3, strlen(f3), 0) != RET_OK) {
  509.         if (fmenu_init(&f, &ed, "", 0, 0) != RET_OK) {
  510.             DError("can't init file getter");
  511.             return(FALSE);
  512.             }
  513.         }
  514.  
  515.     VidCurOff();
  516.     e.kind = E_ACTIV;
  517.     while (!isdone) {
  518.         if (e.kind != E_NONE) fmenu_dis(&f, &ed);
  519.         m_event(&e);
  520.         switch (e.kind) {
  521.  
  522.         case E_ACTIV:
  523.             DNewDisplay();
  524.             DIncrDisplay();
  525.             break;
  526.  
  527.         case E_TERM:
  528.             mac_len = 1;
  529.             mac_ptr = (int *)(m.MacroBody);
  530.             m.MacroBody[0] = KEYQUIT;
  531.             isdone = TRUE;
  532.             break;
  533.         
  534.         case E_BREAK:
  535.             ok = FALSE;
  536.             isdone = TRUE;
  537.             break;
  538.  
  539.         case E_KEY:
  540.             if (e.data == ESC) {
  541.                 ok = FALSE;
  542.                 isdone = TRUE;
  543.                 }
  544.             else    {
  545.                 switch (fmenu_key(&f, &ed, e.data)) {
  546.  
  547.                 case RET_UNKNOWN:
  548.                 case RET_BAD:
  549.                     TBell();
  550.                     break;
  551.  
  552.                 case RET_OK:
  553.                     break;
  554.  
  555.                 case RET_REDISPLAY:
  556.                     DModeLine();
  557.                     break;
  558.  
  559.                 case RET_ACCEPT:
  560.                     isdone = TRUE;
  561.                     break;
  562.  
  563.                 case RET_ABORT:
  564.                     ok = FALSE;
  565.                     isdone = TRUE;
  566.                     break;
  567.                     }
  568.                 }
  569.             break;
  570.             }
  571.         }
  572.  
  573.     fmenu_off(&f, &ed);
  574.     VidCurOn();
  575.     DNewDisplay();
  576.     xstrcpy(fname, ed.edit_buffer);
  577.     return(ok);
  578.     }
  579.  
  580.  
  581. /* ------------------------------------------------------------ */
  582.  
  583. /* Get a key and handle Jaguar-specific translation. */
  584.  
  585. int
  586. JGetKey()
  587.     {
  588.     int chr;
  589.     EVENT e;
  590.  
  591. again:
  592.     if (mac_len > 0) {
  593.         mac_len--;
  594.         chr = *mac_ptr++;
  595.         }
  596.     else    {
  597.         for (chr = KEYNONE; chr == KEYNONE; ) {
  598.             m_event(&e);
  599.             switch (e.kind) {
  600.  
  601.             case E_ACTIV:
  602.                 DNewDisplay();
  603.                 DIncrDisplay();
  604.                 VidCurOn();
  605.                 break;
  606.  
  607.             case E_TERM:
  608.                 chr = KEYQUIT;
  609.                 break;
  610.  
  611.             case E_BREAK:
  612.                 chr = KEYABORT;
  613.                 break;
  614.  
  615.             case E_KEY:
  616.                 chr = e.data;
  617.                 break;
  618.                 }
  619.             }
  620.         }
  621.  
  622.     if (chr & 0xFF) {    /* regular key */
  623.         chr &= 0xFF;
  624.         return(chr);
  625.         }
  626.     else    {
  627.         chr >>= 8;
  628.         chr &= 0xFF;
  629.         if (chr == 0xC8) chr = 133;
  630.         else if (chr >= 0xDB && chr <= 0xE4) {
  631.             J_Char(chr - 0xDB + 1);
  632.             goto again;
  633.             }
  634.         return(chr + 0x100);
  635.         }
  636.     }
  637.  
  638.  
  639. /* ------------------------------------------------------------ */
  640.  
  641. /* Check for a key press.  Return as KIsKey */
  642.  
  643. char
  644. JIsKey()
  645.     {
  646.     EVENT e;
  647.  
  648.     if (mac_len > 0) return('Y');
  649.  
  650.     m_nevent(&e);
  651.     switch (e.kind) {
  652.  
  653.     case E_ACTIV:
  654.         DNewDisplay();
  655.         DIncrDisplay();
  656.         VidCurOn();
  657.         break;
  658.  
  659.     case E_TERM:
  660.         mac_len = 1;
  661.         mac_ptr = (int *)(m.MacroBody);
  662.         m.MacroBody[0] = KEYQUIT;
  663.         
  664.     case E_KEY:
  665.         return('Y');
  666.         /*break;*/
  667.         }
  668.     return('N');
  669.     }
  670.  
  671.  
  672. /* ------------------------------------------------------------ */
  673.  
  674. /* Handle the HP95LX's menu key. */
  675.  
  676. void
  677. JMenu()
  678.     {
  679.     MENUDATA u;
  680.     EVENT e;
  681.     int which = 0;
  682.     FLAG isdone = FALSE;
  683.     FLAG ok = TRUE;
  684.  
  685.     uarg = 0;
  686.     menu_setup(&u, "Help\0Open\0PasteClip\0RegionToClip\0Save\0Quit\0",
  687.         6, 1, NULL, 0, NULL);
  688.  
  689.     VidCurOff();
  690.     menu_on(&u);
  691.  
  692.     while (!isdone) {
  693.         menu_dis(&u);
  694.         DJMenus(0);
  695.         m_event(&e);
  696.         switch (e.kind) {
  697.  
  698.         case E_ACTIV:
  699.             DNewDisplay();
  700.             DIncrDisplay();
  701.             VidCurOff();
  702.             break;
  703.  
  704.         case E_TERM:
  705.             mac_len = 1;
  706.             mac_ptr = (int *)(m.MacroBody);
  707.             m.MacroBody[0] = KEYQUIT;
  708.             isdone = TRUE;
  709.             break;
  710.         
  711.         case E_BREAK:
  712.             mac_len = 1;
  713.             mac_ptr = (int *)(m.MacroBody);
  714.             m.MacroBody[0] = KEYQUIT;
  715.             isdone = TRUE;
  716.             break;
  717.  
  718.         case E_KEY:
  719.             if (e.data == ESC) {
  720.                 which = -1;
  721.                 isdone = TRUE;
  722.                 }
  723.             else    {
  724.                 menu_key(&u, e.data, &which);
  725.                 if (which != -1) isdone = TRUE;
  726.                 }
  727.             break;
  728.             }
  729.         }
  730.  
  731.     menu_off(&u);
  732.     VidCurOn();
  733.  
  734.     switch (which) {
  735.  
  736.     case 0:
  737.         HHelp();
  738.         break;
  739.  
  740.     case 1:
  741.         FFileFind();
  742.         break;
  743.  
  744.     case 2:
  745.         ok = J_Paste();
  746.         break;
  747.  
  748.     case 3:
  749.         ok = J_Copy();
  750.         break;
  751.  
  752.     case 4:
  753.         FFileSave();
  754.         break;
  755.  
  756.     case 5:
  757.         MExit();
  758.         break;
  759.         }
  760.     if (!ok) JGetKey();
  761.     }
  762.  
  763.  
  764. /* ------------------------------------------------------------ */
  765.  
  766. /* Display a message. */
  767.  
  768. void
  769. JMsg(str)
  770.     char *str;
  771.     {
  772.     m_lock();
  773.     message(str, strlen(str), "", 0);
  774.     JGetKey();
  775.     msg_off();
  776.     m_unlock();
  777.     }
  778.  
  779.  
  780. /* ------------------------------------------------------------ */
  781.  
  782. /* Cancel an exit operation. */
  783.  
  784. void
  785. JNoFini()
  786.     {
  787.     EVENT e;
  788.  
  789.     m_no_fini(&e);
  790.     }
  791.  
  792.  
  793. /* ------------------------------------------------------------ */
  794.  
  795. /* Switch input to the specified function key. */
  796.  
  797. void
  798. J_Char(which)
  799.     int which;
  800.     {
  801.     SETTINGS s;
  802.  
  803.     m.MacroFK = which;
  804.     m_get_settings(&s, &m);
  805.  
  806.     if (which == m.MacroFK) {
  807.         mac_ptr = (int *)(m.MacroBody);
  808.         mac_len = m.MacroSize;
  809.         }
  810.     }
  811.  
  812.  
  813. /* ------------------------------------------------------------ */
  814.  
  815. /* Copy the region's contents into the buffer. Return True on
  816. success or False if the caller should wait for a keyboard press. */
  817.  
  818. FLAG
  819. J_Copy()
  820.     {
  821.     char chr;
  822.     FLAG isafter;
  823.  
  824.     if (m_open_cb() != 0) {
  825.         DEchoNM("can't open clipboard");
  826.         return(FALSE);
  827.         }
  828.     if (m_reset_cb("Freyja") != 0) {
  829.         DEchoNM("can't init clipboard");
  830.         m_close_cb();
  831.         return(FALSE);
  832.         }
  833.     m_new_rep("TEXT");
  834.  
  835. /* cycle over the region */
  836.  
  837.     if (isafter = BIsAfterMark(mark)) BMarkSwap(mark);
  838.     BMarkToPoint(cwin->point);
  839.     while (!BIsEnd() && BIsBeforeMark(mark)) {
  840.         chr = BGetCharAdv();
  841.         if (chr == NL) chr = '\xd';
  842.         m_cb_write(&chr, 1);
  843.         }
  844.     BPointToMark(cwin->point);
  845.     if (isafter) BMarkSwap(mark);
  846.  
  847.     m_fini_rep();
  848.     m_close_cb();
  849.     return(TRUE);
  850.     }
  851.  
  852.  
  853. /* ------------------------------------------------------------ */
  854.  
  855. /* Paste the clipboard's contents into the buffer. Return True on
  856. success or False if the caller should wait for a keyboard press. */
  857.  
  858. FLAG
  859. J_Paste()
  860.     {
  861.     int index;
  862.     int len;
  863.     char chr;
  864.     int cnt;
  865.  
  866.     if (m_open_cb() != 0) {
  867.         DEchoNM("can't open clipboard");
  868.         return(FALSE);
  869.         }
  870.     if (m_rep_index("TEXT", &index, &len) != 0) {
  871.         DEchoNM("nothing to paste");
  872.         m_close_cb();
  873.         return(FALSE);
  874.         }
  875.  
  876.     BMarkToPoint(mark);
  877.     for (cnt = 0; cnt < len; cnt++) {
  878.         m_cb_read(index, cnt, &chr, 1);
  879.         if (chr == '\xd') chr = NL;
  880.         if (!BInsChar(chr)) break;
  881.         }
  882.     m_close_cb();
  883.     return(TRUE);
  884.     }
  885.  
  886.  
  887. /* end of SMJAGUAR.C -- HP95LX (Jaguar) Commands and Support, System-Manager
  888. Compliant */
  889.